<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String contextPath = request.getContextPath();
%>
<html>
<head>
	<title></title>
	<jsp:include page="../../inc.jsp"></jsp:include>
</head>
<body>
    <table id="dg" title="客运站管理" class="easyui-datagrid" style="width:1000px;height:700px"
            url="passengerStation!getPassengerStation.action"
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true">
        <thead>
            <tr>
                <th field="id" width="100">客运站id</th>
                <th field="passengerStationName" width="100">客运站名称</th>
                <th field="cityId" width="100">客运站所在城市</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newPassengerStation()">新增客运站信息</a>
    </div>
    
    <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" novalidate>
            <div class="fitem">
                <label>客运站所在城市：</label>
                <input id="startCity" class="easyui-combobox" name="cityId" editable="false"
				        		data-options="valueField:'id',textField:'cityName',url:'city!getCitiesWeb.action'
				        		">
            </div>
            <div class="fitem">
                <label>客运站名称：</label>
                <input name="passengerStationName" class="easyui-textbox" required="true">
            </div>
        </form>
    </div>
    
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="savePassengerStation()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
    </div>
    <script type="text/javascript">
        var url;
        function newPassengerStation(){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增客运站信息');
            $('#fm').form('clear');
            url = 'passengerStation!addPassengerStation.action';
        }
        function editPassengerStation(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑客运站信息');
                $('#fm').form('load',row);
                url = 'update_user.php?id='+row.id;
            }
        }
        function savePassengerStation(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.errorMsg){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                    //    $('#dg').datagrid('reload');    // reload the user data
                        $.messager.show({
                            title: '消息',
                            msg: "添加汽车站成功"
                        });
                    }
                }
            });
        }
        function deletePassengerStation(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','确定删除该客运站信息?',function(r){
                    if (r){
                        $.post('destroy_user.php',{id:row.id},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
    </script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .fitem input{
            width:160px;
        }
    </style>
</body>
</html>